import java.util.Arrays;

/**
 * 1860. 增长的内存泄露
 * https://leetcode-cn.com/problems/incremental-memory-leak/
 */
public class Solutions_1860 {
    public static void main(String[] args) {
//        int memory1 = 2, memory2 = 2;  // output: {3, 1, 0}
        int memory1 = 8, memory2 = 11;  // output: {6, 0, 4}

        int[] result = memLeak(memory1, memory2);
        System.out.println(Arrays.toString(result));
    }

    public static int[] memLeak(int memory1, int memory2) {
        int[] res = new int[3];
        int time = 1;
        while (memory1 >= time || memory2 >= time) {
            // 优先使用剩余内存较多的
            if (memory1 >= memory2) {
                memory1 -= time;
            } else {
                memory2 -= time;
            }
            time ++;
        }
        res[0] = time;
        res[1] = memory1;
        res[2] = memory2;
        return res;
    }
}
